package com.sz.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sz.pojo.RevExp;
import com.sz.pojo.User;
import org.apache.ibatis.annotations.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Mapper
public interface IUserDao extends BaseMapper<RevExp> {
    //根据用户名查密码
    @Select("select password from ffms.user where username=#{username}")
    String getPwdByUn(String username);

    //根据用户名获取name和authority
    @Select("select name,authority from ffms.user where username=#{username}")
    Map getNameAndAuth(String username);

    //根据用户名获取个人信息
    @Select("select name,username,password,authority,remarks from ffms.user where username=#{username}")
    User getUserByUsername(String username);

    //根据用户名修改昵称
    @Update("update ffms.user set `name`=#{name} where username=#{username}")
    int updateName(String username,String name);

    //根据用户名修改密码
    @Update("update ffms.user set `password`=#{password} where username=#{username}")
    int updatePassword(String username,String password);

    //根据用户名修改备注
    @Update("update ffms.user set `remarks`=#{remarks} where username=#{username}")
    int updateRemarks(String username,String remarks);

    //注册新用户
    @Insert("insert into ffms.user (`name`,username,password) values (#{name},#{username},#{password})")
    int addUser(User user);

    //根据用户名查id
    @Select("select userid from ffms.user where username=#{username}")
    int getIdByUsername(String username);

    //获取低权限的所有用户的所有信息
    @Select("select * from ffms.user where authority>=#{auth}")
    List<User> getAllByAuth(int auth);

    //修改任一低权限的用户信息
    @Update("update ffms.user set name=#{name},username=#{username},password=#{password},authority=#{authority},remarks=#{remarks} where userid=#{userid}")
    int updateOneById(User user);

    //删除一条用户信息
    @Delete("delete from ffms.user where userid=#{userid}")
    int deleteOneById(User user);
}
